1. /* scfccos.cpp by K.Tsuru */
  2. // function ID = 9112
  3. /*****************************************
  4. SComplex class
  5. It returns cos(z).
  6. Let z = x+iy,
  7. cos(z) = cos(x)*cosh(y)-i*sin(x)sinh(y)
  8. =(1/2){cos(x)[e^y + e^(-y)]+i*sin(x)[e^(-y) - e^y]
  9. = [exp(iz)+ exp(-iz)]/2
  10. *****************************************/
  11. #ifndef SN_H
  12. #include "sn.h"
  13. #endif
  14. #define UseMultIccos 0
  15. #define UseCSBSccos 1
  16. SComplex Ccos(const SComplex& z){ // z = x+iy
  17. #if UseCSBSccos // 16.14 sec
  18. SDouble c, s, ch, sh, rp, ip;
  19. CosSinBS(Re(z), c, s); // c = cos(x), s = sin(x);
  20. Hyperbolic(Im(z), ch, sh); // ch = cosh(y) sh = sinh(y)
  21. rp = c*ch; ip= -s*sh;
  22. return SComplex(rp, ip);
  23. /*
  24. SDouble rr = Cos(z.Real())*Cosh(z.Imag());
  25. SDouble ri = Sin(z.Real())*Sinh(z.Imag());
  26. ri.ChangeSign(); // ri = -ri
  27. return SComplex(rr, ri);
  28. */
  29. #elif UseMultIccos // 15.9 sec
  30. SComplex eiz = Cexp(MultI(z)), r;
  31. r = eiz + 1.0/eiz;
  32. return r.CsDiv(2L); // faster than r/2
  33. #else // 15.94 sec
  34. SComplex eiz = Cexp(I*z), r;
  35. r = eiz + 1.0/eiz;
  36. return r.CsDiv(2L); // faster than r/2
  37. #endif
  38. }

scfccos.cpp : last modifiled at 2015/08/16 16:36:02(1,085 bytes)
created at 2017/10/06 15:21:28
The creation time of this html file is 2017/10/06 15:27:08 (Fri Oct 06 15:27:08 2017).